// @ts-ignore
import playerPng from "res://assets/player.png"
import BaseSprite from "./base_sprite";

export default class PlayerSprite extends BaseSprite {
    faceMap = {
        1 : 3,
        2 : 0,
        3 : 1,
        4 : 2,
    }
    hNum = 5
    vNum = 4
    xFrame = 0;
    yFrame = 0

    constructor() {
        super();
        this.texture = playerPng;
        this.position = new godot.Vector2(200, 200)

        this.set_hframes(this.hNum)
        this.set_vframes(this.vNum)
        this.set_frame_coords(new godot.Vector2(Math.floor(this.xFrame),this.yFrame))

        this.isInputMove = true
    }

    _process(delta: number): void {
        super._process(delta);
        
        // 播放动画
        if(this.face > 0){
            let yFrame = this.faceMap[this.face]
            if(this.yFrame != yFrame){
                this.xFrame = 0
                this.yFrame = yFrame
            }else{
                if(this.xFrame < this.hNum){
                    this.xFrame = this.xFrame + 0.3
                }else{
                    this.xFrame = 0
                }
            }
        }

        this.xFrame = this.xFrame > 5 ? 0 : this.xFrame;

        this.set_frame_coords(new godot.Vector2(Math.floor(this.xFrame),this.yFrame))
    }
}